// ignore_for_file: must_be_immutable

import 'package:dmz/request/config.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:cached_network_image/cached_network_image.dart';

class DefaultText extends Text {
  dynamic text;
  double size;

  DefaultText(this.text, this.size,
      {super.key,
      Color? textColor,
      int? maxLines,
      FontWeight? fontWeight,
      TextOverflow? overflow,
      String? fontFamily,
      TextAlign? textAlign})
      : super(text,
            maxLines: maxLines,
            softWrap: true,
            overflow: overflow,
            textAlign: textAlign,
            style: TextStyle(
                fontFamily: fontFamily,
                fontSize: size,
                color: textColor,
                fontWeight: fontWeight));
}

class DefaultBtn extends StatelessWidget {
  final Function() click;
  final String title;
  final Color? textColor;
  final double? size;
  final Color? backColor;
  final double? height;
  final double? width;
  final FontWeight? fontWeight;
  const DefaultBtn(
      {super.key,
      required this.click,
      required this.title,
      this.textColor,
      this.size,
      this.backColor,
      this.height,
      this.width,
      this.fontWeight});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: click,
        child: Container(
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: backColor,
            gradient: backColor != null
                ? null
                : const LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [Color(0xFF6DD400), Color(0xFF20C468)]),
            borderRadius: BorderRadius.circular(height ?? 120.0),
          ),
          height: height ?? 120.sp,
          width: width ?? MediaQuery.of(context).size.width - 80.sp,
          // margin: EdgeInsets.only(left: 40.sp, right: 40.sp, top: 88.sp),
          child: DefaultText(title, size ?? 32.sp,
              textColor: textColor ?? Colors.white,
              fontWeight: fontWeight ?? FontWeight.w600),
        ));
  }
}

class DefaultNetWorkImage extends CachedNetworkImage {
  String url;

  DefaultNetWorkImage(this.url,
      {super.key,
      double? width,
      double? height,
      String? placeholder,
      String? errImage,
      double? otherWidth,
      double? otherHight,
      Widget? otherWidget,
      BoxFit? fit})
      : super(
            imageUrl: '${RequestConfig.oss}$url',
            height: height,
            width: width,
            fit: fit ?? BoxFit.cover,
            placeholder: (context, string) {
              return otherWidget ??
                  Container(
                      color: Colors.transparent,
                      child: Image.asset(
                        placeholder ??
                            'assets/images/home/main/position_image.png',
                        width: otherWidth ?? width,
                        height: otherHight ?? height,
                        fit: fit ?? BoxFit.cover,
                      ));
            },
            errorWidget: (context, url, error) {
              return otherWidget ??
                  Container(
                      color: Colors.transparent,
                      child: Image.asset(
                        errImage ??
                            'assets/images/home/main/position_image.png',
                        width: otherWidth ?? width,
                        height: otherHight ?? height,
                        fit: fit ?? BoxFit.cover,
                      ));
            });
}

class DefaultIconBtn extends IconButton {
  String image;

  bool isSelect;

  DefaultIconBtn(this.image, this.isSelect,
      {super.key,
      String? selectImage,
      double? width,
      double? height,
      Function()? click})
      : super(
            icon: Image.asset(image, width: width, height: height),
            selectedIcon: selectImage == null
                ? null
                : Image.asset(selectImage, width: width, height: height),
            onPressed: click,
            isSelected: isSelect,
            padding: const EdgeInsets.all(0));
}
